Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

nice_things/storage/destructor_add.sh

destructor_add

Since 0.3.0 · Source

import "{ destructor_add }" from nice_things/storage/destructor_add.sh

Synopsis
destructor_add <command> [<arg>…]

Configuration

Description
Register a destructor command/function to be executed on program exit. This function can be invoked many times to register many destructors. Once added, destructors cannot be removed, so destructor functions should ideally be idempotent.

This function registers a trap, taking care to make sure it is executed on any shell no matter if the process exits normally or is terminated by a signal.

Note

When destructors are in use, traps for EXIT and the usual termination signals HUP INT QUIT ABRT ALRM TERM should not be configured manually, or they will override the destructors configured through this function.

Options

Operands

  • <command>: The destructor command.
  • <arg>: Optional argument to <command>.

Stdin

Stdout

Stderr

Exit status

  • 0: Successful completion.
  • 11: Invalid or missing arguments (abort).

Abort
Aborts on invalid or missing arguments.

Usage examples

# Delete a temporary file on exit
destructor_add rm -f /path/to/temp/file